#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
typedef struct stu
{
    int x;
    int d;
    int c;
}stu;
stu arr[10001];
stu dc1[10001]; stu dc2[10001]; stu dc3[10001]; stu dc4[10001];
void mysort(stu* p, int count)
{
    stu tmp;
    for (int m = 0; m < count - 1; m++)
    {
        for (int n = 0; n < count - 1 - m; n++)
        {
            if (((p + n)->d + (p + n)->c) < ((p + n + 1)->d + (p + n + 1)->c))
            {
                tmp = *(p + n);
                *(p + n) = *(p + n + 1);
                *(p + n + 1) = tmp;
            }
            else if (((p + n)->d + (p + n)->c) == ((p + n + 1)->d + (p + n + 1)->c))
            {
                if ((p + n)->d < (p + n + 1)->d)
                {
                    tmp = *(p + n);
                    *(p + n) = *(p + n + 1);
                    *(p + n + 1) = tmp;
                }
                else if ((p + n)->d == (p + n + 1)->d)
                {
                    if ((p + n)->x > (p + n + 1)->x)
                    {
                        tmp = *(p + n);
                        *(p + n) = *(p + n + 1);
                        *(p + n + 1) = tmp;
                    }
                }
            }
        }
    }
}
int main()
{
    int a = 0;
    scanf("%d", &a);
    int j = 0;
    int y = 0;
    scanf("%d%d", &j, &y);

    for (int i = 0; i < a; i++)
    {
        scanf("%d", &arr[i].x);
        scanf("%d", &arr[i].d);
        scanf("%d", &arr[i].c);
    }
    int count = 0;
    for (int i = 0; i < a; i++)
    {
        if (arr[i].d >= j && arr[i].c >= j)
        {
            count++;
        }
    }
    printf("%d\n", count);
    int count1 = 0; int count2 = 0; int count3 = 0; int count4 = 0;
    for (int i = 0; i < a; i++)
    {
        if (arr[i].d >= y && arr[i].c >= y)
        {
            dc1[count1++] = arr[i];
        }
        else if (arr[i].d >= y && arr[i].c >= j)
        {
            dc2[count2++] = arr[i];
        }
        else if (arr[i].d >= j && arr[i].c >= j && arr[i].d >= arr[i].c)
        {
            dc3[count3++] = arr[i];
        }
        else if (arr[i].d >= j && arr[i].c >= j)
        {
            dc4[count4++] = arr[i];
        }
    }
    mysort(dc1, count1);
    mysort(dc2, count2);
    mysort(dc3, count3);
    mysort(dc4, count4);
    for (int i = 0; i < count1; i++)
    {
        printf("%d %d %d\n", dc1[i].x, dc1[i].d, dc1[i].c);
    }
    for (int i = 0; i < count2; i++)
    {
        printf("%d %d %d\n", dc2[i].x, dc2[i].d, dc2[i].c);
    }
    for (int i = 0; i < count3; i++)
    {
        printf("%d %d %d\n", dc3[i].x, dc3[i].d, dc3[i].c);
    }
    for (int i = 0; i < count4; i++)
    {
        printf("%d %d %d\n", dc4[i].x, dc4[i].d, dc4[i].c);
    }
    return 0;
}